﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ModuleDuoc
{
    public partial class frmExtend : Form
    {
        public frmExtend()
        {
            InitializeComponent();
        }
        public void GetStr(String str1, String str2, String tongtien, String khachdua)
        {
            this.txtTenKH.Text = str1;
            this.txtDiaChi.Text = str2;
            this.txtTongTien.Text = tongtien;
            this.txtKhachDua.Text = khachdua;
        }
        public void GetDGV(DataGridView dgvExtend)
        {
            try
            {
                this.dgvExtend.Rows.Clear();
                //this.dgvExtend = dgvEx;
                for (int i = 0; i < dgvExtend.Rows.Count; i++)
                {
                    this.dgvExtend.Rows.Add(dgvExtend.Rows[i].Cells["MaVach"].Value.ToString(), dgvExtend.Rows[i].Cells["TenVT"].Value.ToString(), dgvExtend.Rows[i].Cells["DVT"].Value.ToString(), dgvExtend.Rows[i].Cells["SoLuong"].Value.ToString(), String.Format("{0:0,0}", Double.Parse(dgvExtend.Rows[i].Cells["DonGia"].Value.ToString())), dgvExtend.Rows[i].Cells["Vat"].Value.ToString(), String.Format("{0:0,0}", Double.Parse(dgvExtend.Rows[i].Cells["ThanhTien"].Value.ToString())));
                }
                this.lblBangChu.Text = DICHSO.XL_DOC_SO.DOC_SO_CHUOI(Double.Parse(this.txtTongTien.Text.ToString()), "đồng", "", 0);
            }
            catch (Exception)
            { }
        }

        private void frmExtend_Load(object sender, EventArgs e)
        {
            frmHD_BanLe f2 = new frmHD_BanLe();
            f2.MySetStr = new frmHD_BanLe.SetStr(GetStr);
            f2.MySetDgv = new frmHD_BanLe.SetDGV(GetDGV);
            f2.Show();
        }

        private void txtKhachDua_TextChanged(object sender, EventArgs e)
        {
            if (Double.Parse(this.txtKhachDua.Text) - Double.Parse(this.txtTongTien.Text) < 0)
            {
                this.label19.Text = "Thiếu";
            }
            else
            {
                this.label19.Text = "Trả lại";
            }
            Double kd;
            Double tl;
            Double tt;
            try
            {
                if (this.txtKhachDua.Text != "")
                {
                    kd = Double.Parse(this.txtKhachDua.Text);
                    tt = Double.Parse(this.txtTongTien.Text);
                    tl = tt - kd;
                    //String.Format("{0:0,0 vnđ}", 20000000)
                    this.txtTraLai.Text = String.Format("{0:0,0}", tl);
                }
                else
                {
                    kd = 0;
                    this.txtTraLai.Text = "";
                }
            }
            catch (Exception)
            { }
        }
    }
}
